/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.sistemas.sisgear.JSQLParser;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import net.sf.jsqlparser.expression.*;
import net.sf.jsqlparser.expression.operators.arithmetic.*;
import net.sf.jsqlparser.expression.operators.conditional.*;
import net.sf.jsqlparser.expression.operators.relational.*;
import net.sf.jsqlparser.schema.Column;
import net.sf.jsqlparser.schema.Table;
import net.sf.jsqlparser.statement.select.*;

/**
 *
 * @author Jean
 */
public class TablesNamesFinder implements SelectVisitor, FromItemVisitor,ExpressionVisitor
                                           ,ItemsListVisitor{
    private List<String> tables;
    private List<OrderByElement> orderByElements;
    private List<SelectItem> SelectElements;
    

    
    public TablesNamesFinder(){
        System.out.println("ESTO ES LA CLASE: "+this.getClass().getName());
    }
    
    public List getTableList(Select select) {
        tables = new ArrayList();
        select.getSelectBody().accept(this);
        return tables;
    }

    public List getOrderByElements(Select select) {
        
      //  select.getSelectBody().accept(this);
        return orderByElements;
    }
    public List getSelectElements(Select select) {
        //select.getSelectBody().accept(this);
        return SelectElements;
    }
    
    public void visit(PlainSelect plainSelect) {
        System.out.println("aqui 1");
        plainSelect.getFromItem().accept(this);
        
        orderByElements = plainSelect.getOrderByElements();
        SelectElements = plainSelect.getSelectItems();
        
        if (plainSelect.getJoins() != null) {
            for (Iterator joinsIt = plainSelect.getJoins().iterator(); joinsIt.hasNext();) {
                Join join = (Join) joinsIt.next();
                join.getRightItem().accept(this);
            }
        }
        if (plainSelect.getWhere() != null){
        }
            //plainSelect.getWhere().accept(this);

    }

   

    public void visit(Table tableName) {
        System.out.println("aqui 2");
        Alias tableWholeName = tableName.getAlias();
        String nombreTabla = tableName.getName();
        
        String nombre = nombreTabla +" "+tableWholeName.getName();
        tables.add(nombre);
    }

    public void visit(SubSelect subSelect) {
        System.out.println("aqui 3");
        subSelect.getSelectBody().accept(this);
    }
//and other visit implement ....

    @Override
    public void visit(SubJoin sj) {
        System.out.println("aqui 4");
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public void visit(NullValue nv) {
        System.out.println("aqui 5");
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public void visit(Function fnctn) {
        System.out.println("aqui 6");
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

   

    @Override
    public void visit(JdbcParameter jp) {
        System.out.println("aqui 7");
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public void visit(DoubleValue dv) {
        System.out.println("aqui 8");
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public void visit(LongValue lv) {
        System.out.println("aqui 9");
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public void visit(DateValue dv) {
        System.out.println("aqui 10");
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public void visit(TimeValue tv) {
        System.out.println("aqui 11");
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public void visit(TimestampValue tv) {
        System.out.println("aqui 12");
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public void visit(Parenthesis prnths) {
        System.out.println("aqui 13");
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public void visit(StringValue sv) {
        System.out.println("aqui 14");
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public void visit(Addition adtn) {
        System.out.println("aqui 15");
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public void visit(Division dvsn) {
        System.out.println("aqui 16");
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public void visit(Multiplication m) {
        System.out.println("aqui 17");
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public void visit(Subtraction s) {
        System.out.println("aqui 18");
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public void visit(AndExpression ae) {
        System.out.println("aqui 19");
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public void visit(OrExpression oe) {
        System.out.println("aqui 20");
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public void visit(Between btwn) {
        System.out.println("aqui 21");
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public void visit(EqualsTo et) {
        System.out.println("aqui 22");
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public void visit(GreaterThan gt) {
        System.out.println("aqui 23");
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public void visit(GreaterThanEquals gte) {
        System.out.println("aqui 24");
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public void visit(InExpression ie) {
        System.out.println("aqui 25");
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public void visit(IsNullExpression ine) {
        System.out.println("aqui 26");
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public void visit(LikeExpression le) {
        System.out.println("aqui 27");
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public void visit(MinorThan mt) {
        System.out.println("aqui 28");
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public void visit(MinorThanEquals mte) {
        System.out.println("aqui 29");
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public void visit(NotEqualsTo net) {
        System.out.println("aqui 30");
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public void visit(Column column) {
        System.out.println("aqui 31");
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public void visit(CaseExpression ce) {
        System.out.println("aqui 32");
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public void visit(WhenClause wc) {
        System.out.println("aqui 33");
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public void visit(ExistsExpression ee) {
        System.out.println("aqui 34");
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public void visit(AllComparisonExpression ace) {
        System.out.println("aqui 35");
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public void visit(AnyComparisonExpression ace) {
        System.out.println("aqui 36");
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public void visit(Concat concat) {
        System.out.println("aqui 37");
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public void visit(Matches mtchs) {
        System.out.println("aqui 38");
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public void visit(BitwiseAnd ba) {
        System.out.println("aqui 39");
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public void visit(BitwiseOr bo) {
        System.out.println("aqui 40");
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public void visit(BitwiseXor bx) {
        System.out.println("aqui 41");
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public void visit(ExpressionList el) {
        System.out.println("aqui 42");
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public void visit(SetOperationList sol) {
        System.out.println("aqui 43");
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public void visit(WithItem wi) {
        System.out.println("aqui 44");
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public void visit(LateralSubSelect lss) {
        System.out.println("aqui 45");
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public void visit(ValuesList vl) {
        System.out.println("aqui 46");
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public void visit(SignedExpression se) {
        System.out.println("aqui 47");
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public void visit(JdbcNamedParameter jnp) {
        System.out.println("aqui 48");
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public void visit(CastExpression ce) {
        System.out.println("aqui 49");
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public void visit(Modulo modulo) {
        System.out.println("aqui 50");
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public void visit(AnalyticExpression ae) {
        System.out.println("aqui 51");
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public void visit(ExtractExpression ee) {
        System.out.println("aqui 52");
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public void visit(IntervalExpression ie) {
        System.out.println("aqui 53");
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public void visit(OracleHierarchicalExpression ohe) {
        System.out.println("aqui 54");
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public void visit(RegExpMatchOperator remo) {
        System.out.println("aqui 55");
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public void visit(MultiExpressionList mel) {
        System.out.println("aqui 56");
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }    
}
